﻿using System;
using System.Collections;
using System.Collections.Generic;
using NonLeagueExplorer.Data.Interfaces;

namespace NonLeagueExplorer.Data
{
    public class FixtureList : IFixtureList, IEnumerable
    {
        private List<IFixture> m_Fixtures = new List<IFixture>();

        public FixtureList()
        {

        }

        public FixtureList(IEnumerable<IFixture> p_Fixtures)
        {
            m_Fixtures = new List<IFixture>(p_Fixtures);
        }

        public IFixture this[int index]
        {
            get
            {
                return m_Fixtures[index];
            }
        }

        #region IFixtureList Members

        public void Add(IFixture p_Fixture)
        {
            m_Fixtures.Add(p_Fixture);
        }

        public void Remove(IFixture p_Fixture)
        {
            m_Fixtures.Remove(p_Fixture);
        }

        public void Postpone(IFixture p_Fixture)
        {
            int pos = Find(p_Fixture);
            m_Fixtures[pos].Postpone();
        }

        public void Postpone(IFixture p_Fixture, DateTime p_NewDate)
        {
            int pos = Find(p_Fixture);
            m_Fixtures[pos].Postpone();
            m_Fixtures[pos].SetDate(p_NewDate);
        }

        public void Abandon(IFixture p_Fixture)
        {
            int pos = Find(p_Fixture);
            m_Fixtures[pos].Abandon();
        }

        public int Size()
        {
            return m_Fixtures.Count;
        }

        public void Clear()
        {
            m_Fixtures.Clear();
        }
        #endregion

        #region IEnumerable Members

        public IEnumerator GetEnumerator()
        {
            return (IEnumerator)m_Fixtures.GetEnumerator();
        }

        #endregion

        protected int Find(IFixture p_Fixture)
        {
            return m_Fixtures.IndexOf(p_Fixture);
        }
    }
}
